<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">

    </head>
</head>


<body>
<br><br><br>

<form action="/shop/memberManagement">
    <input type="hidden" id="type" name="type" value="${type}">

    <div class="layui-input-inline">
        <input type="text" name="name" id="name" value="${name}" placeholder="请输入会员id、支付宝号" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-input-inline" style="width:80px">
        <button class="layui-btn"  lay-submit="" lay-filter="/shop/memberManagement"><i class="layui-icon">&#xe615;</i>搜索</button>
    </div>
</form>
<form class="layui-form">
 <table class="layui-table">
            <thead>
            <tr >
                <th>ID</th>
                <th>支付宝ID</th>
                <th>姓名</th>
                <th>手机号码</th>
                <th>支付宝账号</th>
                <th>身份证号码</th>
                <th>操作</th>
                <th>拉黑会员</th>
                <th>成为代理商</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="rl">
                <tr>
                    <td>${rl.id}</td>
                    <td>${rl.alipayId}</td>
                    <td>${rl.realName}</td>
                    <td>${rl.tel}</td>
                    <td>${rl.alipayAccount}</td>
                    <td>${rl.IDCardNumber=='null'?'':rl.IDCardNumber}</td>
                    <td>
                        <button class="layui-btn" type="button" onclick="update('${rl.id}');">售卡记录</button>
                        <button class="layui-btn" type="button" onclick="update1('${rl.id}');">配置返利</button>
                        <button class="layui-btn" type="button" onclick="update2('${rl.id}');">资金记录</button>
                        <button class="layui-btn" type="button" onclick="update3('${rl.id}');">下级列表</button>
                    </td>

                    <td>
                        <input type="checkbox" id="${rl.id}" lay-filter="switch" <c:if test="${rl.forbid==1}">checked</c:if> lay-skin="switch" lay-text="开启|关闭">
                    </td>
                    <td>
                        <input type="checkbox" id="${rl.id}" lay-filter="agent" <c:if test="${rl.agent=='0'}">checked</c:if> lay-skin="switch" lay-text="代理|用户${rl.agent}">
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
</form>
<div id="fenye"></div>

<div id="under" style="margin-top: 20rem"></div>

<script>
    layui.use('form', function(){
        var form = layui.form;

        form.on('switch(switch)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象


            $.ajax({
                url:'/member/forbid',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    memberId:data.elem.id,
                    checked:data.elem.checked
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){

                },
                success:function(reData){
                    if (""!=reData){
                        layer.alert("保存成功", {icon: 6},function () {
                            // 获得frame索引
                            //关闭当前frame
                            layer.closeAll();
                        });
                    }else {
                        layer.alert("保存失败", {icon: 5});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });



        });
        form.on('switch(agent)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象


            $.ajax({
                url:'/member/agent',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    memberId:data.elem.id,
                    checked:data.elem.checked
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){

                },
                success:function(reData){
                    if (""!=reData){
                        layer.alert("保存成功", {icon: 6},function () {
                            // 获得frame索引
                            //关闭当前frame
                            layer.closeAll();
                        });
                    }else {
                        layer.alert("保存失败", {icon: 5});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });



        });
    });
</script>


<script>
    var type=$("#type").val();
    var name=$("#name").val();
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        laypage.render({
            elem: 'fenye'
            ,count: ${pageUtil.totalRows}
            ,limit:10//数据总数，从服务端得到
            ,curr:${pageUtil.currentPage}
            ,hash:true
            ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数
                //首次不执行
                if(!first){
                    window.location.href="/shop/memberManagement?page="+obj.curr+"&limit="+obj.limit+"&type="+type+"&name="+name;
                }
            }
        });
    });

    function update(id) {
       layer.open({
           type: 2,
           area: ['80%', '80%'],
           title:'售卡记录',
           offset: '20px',
           shadeClose:true,
           content: '/shop/sellCardrecords?id='+id,
           end:function() {
               console.log("页面要刷新");
               window.location.reload();
           }
       });
    }

    function update1(id) {
        layer.open({
            type: 2,
            area: ['90%', '80%'],
            title:'配置返利',
            offset: '20px',
            shadeClose:true,
            content: '/shop/agent?id='+id,
            end:function() {
                console.log("页面要刷新");
                window.location.reload();

            }
        });
    }

    function update2(id) {
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            title:'资金记录',
            offset: '20px',
            shadeClose:true,
            content: '/shop/moneyRecord?id='+id,
            end:function() {
                console.log("页面要刷新");
                window.location.reload();

            }
        });
    }

    function update3(id) {
        layer.open({
            type: 2,
            area: ['50%', '80%'],
            title:'下级列表',
            offset: '20px',
            shadeClose:true,
            content: '/shop/subordinate?id='+id,
            end:function() {
                console.log("页面要刷新");
                window.location.reload();

            }
        });
    }


</script>
</body>
</html>
